using Net;
using System.Collections.Generic;
using System.IO;

public enum UserUpdateType
{
    userUpdateNull = 0,
    password = 1,
    other = 2,
}

/// <summary>
/// // id = 1, desc = "用户注册"
/// </summary>
public class U2LS_UserRegisterRequest : BaseMessage
{
    public override short MsgId => MessageDefine.U2LS_UserRegisterRequest;
    public string account;  //账号（必填）
    private readonly uint tag_account = ProtoHelper.CalcTag(1, "string");
    public string phone;  //以及区号与手机号合并的形式，+8613112345678、+86131-1234-1234
    private readonly uint tag_phone = ProtoHelper.CalcTag(2, "string");
    public string nickname;  //昵称（请填写1~8个汉字）
    private readonly uint tag_nickname = ProtoHelper.CalcTag(3, "string");
    public string password;  //密码（必填）
    private readonly uint tag_password = ProtoHelper.CalcTag(4, "string");
    public string confirm_pwd;  //确认密码（必填）
    private readonly uint tag_confirm_pwd = ProtoHelper.CalcTag(5, "string");

    public override void Deserialize(byte[] data,ref int offset)
    {
        int newOffset = offset;
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_account);
        if (tag_account == tag_read_account)
        {
            offset = newOffset;
            account = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_phone);
        if (tag_phone == tag_read_phone)
        {
            offset = newOffset;
            phone = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_nickname);
        if (tag_nickname == tag_read_nickname)
        {
            offset = newOffset;
            nickname = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_password);
        if (tag_password == tag_read_password)
        {
            offset = newOffset;
            password = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_confirm_pwd);
        if (tag_confirm_pwd == tag_read_confirm_pwd)
        {
            offset = newOffset;
            confirm_pwd = ProtoHelper.ReadString(data, ref offset);
        }

    }

    public override byte[] Serialize()
    {
        byte[] __bytes;
        using MemoryStream ms = new MemoryStream();
        using BinaryWriter bw = new BinaryWriter(ms);

        __bytes = ProtoHelper.WriteString(account);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(1, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(phone);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(2, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(nickname);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(3, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(password);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(4, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(confirm_pwd);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(5, "string"));
            bw.Write(__bytes);
        }

        return ms.ToArray();
    }
}

/// <summary>
/// // id = 2, desc = "用户登录"
/// </summary>
public class U2LS_UserLoginRequest : BaseMessage
{
    public override short MsgId => MessageDefine.U2LS_UserLoginRequest;
    public string phone;  //手机号（与账号二选一）
    private readonly uint tag_phone = ProtoHelper.CalcTag(1, "string");
    public string account;  //账号（与手机号二选一）
    private readonly uint tag_account = ProtoHelper.CalcTag(2, "string");
    public string password;  //密码
    private readonly uint tag_password = ProtoHelper.CalcTag(3, "string");
    public int login_type;  //登录类型（1账号,2手机）
    private readonly uint tag_login_type = ProtoHelper.CalcTag(4, "int32");

    public override void Deserialize(byte[] data,ref int offset)
    {
        int newOffset = offset;
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_phone);
        if (tag_phone == tag_read_phone)
        {
            offset = newOffset;
            phone = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_account);
        if (tag_account == tag_read_account)
        {
            offset = newOffset;
            account = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_password);
        if (tag_password == tag_read_password)
        {
            offset = newOffset;
            password = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_login_type);
        if (tag_login_type == tag_read_login_type)
        {
            offset = newOffset;
            login_type = ProtoHelper.ReadInt32(data, ref offset);
        }

    }

    public override byte[] Serialize()
    {
        byte[] __bytes;
        using MemoryStream ms = new MemoryStream();
        using BinaryWriter bw = new BinaryWriter(ms);

        __bytes = ProtoHelper.WriteString(phone);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(1, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(account);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(2, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(password);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(3, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteInt32(login_type);
        {
            bw.Write(ProtoHelper.WriteTag(4, "int32"));
            bw.Write(__bytes);
        }

        return ms.ToArray();
    }
}

/// <summary>
/// // id = 3, desc = "登录与注册的响应"
/// </summary>
public class LS2U_UserLoginResponse : BaseMessage
{
    public override short MsgId => MessageDefine.LS2U_UserLoginResponse;
    public string sign;  //签名
    private readonly uint tag_sign = ProtoHelper.CalcTag(1, "string");
    public long user_id;  //玩家id
    private readonly uint tag_user_id = ProtoHelper.CalcTag(2, "int64");
    public string account;  //账号
    private readonly uint tag_account = ProtoHelper.CalcTag(3, "string");
    public string phone_area;  //手机区号
    private readonly uint tag_phone_area = ProtoHelper.CalcTag(4, "string");
    public string phone;  //手机号
    private readonly uint tag_phone = ProtoHelper.CalcTag(5, "string");
    public int identity;  //身份（普通玩家可忽略此项为0，-1超级管理员）
    private readonly uint tag_identity = ProtoHelper.CalcTag(6, "int32");
    public string nickname;  //昵称
    private readonly uint tag_nickname = ProtoHelper.CalcTag(7, "string");
    public string signature;  //个性签名
    private readonly uint tag_signature = ProtoHelper.CalcTag(8, "string");
    public UserLoginResponseWalletData wallet_info;  //钱包数据
    private readonly uint tag_wallet_info = ProtoHelper.CalcTag(9, WireType.LengthDelimited);

    public override void Deserialize(byte[] data,ref int offset)
    {
        int newOffset = offset;
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_sign);
        if (tag_sign == tag_read_sign)
        {
            offset = newOffset;
            sign = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_user_id);
        if (tag_user_id == tag_read_user_id)
        {
            offset = newOffset;
            user_id = ProtoHelper.ReadInt64(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_account);
        if (tag_account == tag_read_account)
        {
            offset = newOffset;
            account = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_phone_area);
        if (tag_phone_area == tag_read_phone_area)
        {
            offset = newOffset;
            phone_area = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_phone);
        if (tag_phone == tag_read_phone)
        {
            offset = newOffset;
            phone = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_identity);
        if (tag_identity == tag_read_identity)
        {
            offset = newOffset;
            identity = ProtoHelper.ReadInt32(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_nickname);
        if (tag_nickname == tag_read_nickname)
        {
            offset = newOffset;
            nickname = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_signature);
        if (tag_signature == tag_read_signature)
        {
            offset = newOffset;
            signature = ProtoHelper.ReadString(data, ref offset);
        }

        wallet_info = new UserLoginResponseWalletData();
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_wallet_info);
        if (tag_wallet_info == tag_read_wallet_info)
        {
            offset = newOffset;
            ProtoHelper.ReadLength(data, ref offset);
            wallet_info.Deserialize(data,ref offset);
        }

    }

    public override byte[] Serialize()
    {
        byte[] __bytes;
        using MemoryStream ms = new MemoryStream();
        using BinaryWriter bw = new BinaryWriter(ms);

        __bytes = ProtoHelper.WriteString(sign);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(1, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteInt64(user_id);
        {
            bw.Write(ProtoHelper.WriteTag(2, "int64"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(account);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(3, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(phone_area);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(4, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(phone);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(5, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteInt32(identity);
        {
            bw.Write(ProtoHelper.WriteTag(6, "int32"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(nickname);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(7, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(signature);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(8, "string"));
            bw.Write(__bytes);
        }

        if (wallet_info != null)
        {
            __bytes = wallet_info.Serialize();
            if (__bytes != null && __bytes.Length > 0)
            {
                bw.Write(ProtoHelper.WriteTag(9, WireType.LengthDelimited));
                bw.Write(ProtoHelper.WriteInt32(__bytes.Length));
                bw.Write(__bytes);
            }
        }

        return ms.ToArray();
    }
}

public class UserLoginResponseWalletData : IMessageSerializer
{
    public long gold;  //金币
    private readonly uint tag_gold = ProtoHelper.CalcTag(1, "int64");
    public long diamond;  //钻石
    private readonly uint tag_diamond = ProtoHelper.CalcTag(2, "int64");

    public void Deserialize(byte[] data,ref int offset)
    {
        int newOffset = offset;
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_gold);
        if (tag_gold == tag_read_gold)
        {
            offset = newOffset;
            gold = ProtoHelper.ReadInt64(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_diamond);
        if (tag_diamond == tag_read_diamond)
        {
            offset = newOffset;
            diamond = ProtoHelper.ReadInt64(data, ref offset);
        }

    }

    public byte[] Serialize()
    {
        byte[] __bytes;
        using MemoryStream ms = new MemoryStream();
        using BinaryWriter bw = new BinaryWriter(ms);

        __bytes = ProtoHelper.WriteInt64(gold);
        {
            bw.Write(ProtoHelper.WriteTag(1, "int64"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteInt64(diamond);
        {
            bw.Write(ProtoHelper.WriteTag(2, "int64"));
            bw.Write(__bytes);
        }

        return ms.ToArray();
    }
}

/// <summary>
/// // id = 4, desc = "用户修改信息"
/// </summary>
public class U2LS_UserUpdateInfoRequest : BaseMessage
{
    public override short MsgId => MessageDefine.U2LS_UserUpdateInfoRequest;
    public UserUpdateType update_type;
    private readonly uint tag_update_type = ProtoHelper.CalcTag(1, WireType.Varint);
    public UserUpdateInfoPwd pwd;  //密码
    private readonly uint tag_pwd = ProtoHelper.CalcTag(2, WireType.LengthDelimited);
    public UserUpdateInfoOther info;  //其他信息
    private readonly uint tag_info = ProtoHelper.CalcTag(3, WireType.LengthDelimited);

    public override void Deserialize(byte[] data,ref int offset)
    {
        int newOffset = offset;
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_update_type);
        if (tag_update_type == tag_read_update_type)
        {
            offset = newOffset;
            update_type = (UserUpdateType)ProtoHelper.ReadInt32(data, ref offset);
        }

        pwd = new UserUpdateInfoPwd();
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_pwd);
        if (tag_pwd == tag_read_pwd)
        {
            offset = newOffset;
            ProtoHelper.ReadLength(data, ref offset);
            pwd.Deserialize(data,ref offset);
        }

        info = new UserUpdateInfoOther();
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_info);
        if (tag_info == tag_read_info)
        {
            offset = newOffset;
            ProtoHelper.ReadLength(data, ref offset);
            info.Deserialize(data,ref offset);
        }

    }

    public override byte[] Serialize()
    {
        byte[] __bytes;
        using MemoryStream ms = new MemoryStream();
        using BinaryWriter bw = new BinaryWriter(ms);

        bw.Write(ProtoHelper.WriteTag(1, WireType.Varint));
        bw.Write(ProtoHelper.WriteInt32((int)update_type));

        if (pwd != null)
        {
            __bytes = pwd.Serialize();
            if (__bytes != null && __bytes.Length > 0)
            {
                bw.Write(ProtoHelper.WriteTag(2, WireType.LengthDelimited));
                bw.Write(ProtoHelper.WriteInt32(__bytes.Length));
                bw.Write(__bytes);
            }
        }

        if (info != null)
        {
            __bytes = info.Serialize();
            if (__bytes != null && __bytes.Length > 0)
            {
                bw.Write(ProtoHelper.WriteTag(3, WireType.LengthDelimited));
                bw.Write(ProtoHelper.WriteInt32(__bytes.Length));
                bw.Write(__bytes);
            }
        }

        return ms.ToArray();
    }
}

public class UserUpdateInfoPwd : IMessageSerializer
{
    public string password;  //密码
    private readonly uint tag_password = ProtoHelper.CalcTag(1, "string");
    public string confirm_pwd;  //确认密码
    private readonly uint tag_confirm_pwd = ProtoHelper.CalcTag(2, "string");

    public void Deserialize(byte[] data,ref int offset)
    {
        int newOffset = offset;
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_password);
        if (tag_password == tag_read_password)
        {
            offset = newOffset;
            password = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_confirm_pwd);
        if (tag_confirm_pwd == tag_read_confirm_pwd)
        {
            offset = newOffset;
            confirm_pwd = ProtoHelper.ReadString(data, ref offset);
        }

    }

    public byte[] Serialize()
    {
        byte[] __bytes;
        using MemoryStream ms = new MemoryStream();
        using BinaryWriter bw = new BinaryWriter(ms);

        __bytes = ProtoHelper.WriteString(password);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(1, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(confirm_pwd);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(2, "string"));
            bw.Write(__bytes);
        }

        return ms.ToArray();
    }
}

public class UserUpdateInfoOther : IMessageSerializer
{
    public string nickname;  //昵称（请填写1~8个汉字）
    private readonly uint tag_nickname = ProtoHelper.CalcTag(1, "string");
    public string signature;  //个性签名
    private readonly uint tag_signature = ProtoHelper.CalcTag(2, "string");

    public void Deserialize(byte[] data,ref int offset)
    {
        int newOffset = offset;
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_nickname);
        if (tag_nickname == tag_read_nickname)
        {
            offset = newOffset;
            nickname = ProtoHelper.ReadString(data, ref offset);
        }

        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_signature);
        if (tag_signature == tag_read_signature)
        {
            offset = newOffset;
            signature = ProtoHelper.ReadString(data, ref offset);
        }

    }

    public byte[] Serialize()
    {
        byte[] __bytes;
        using MemoryStream ms = new MemoryStream();
        using BinaryWriter bw = new BinaryWriter(ms);

        __bytes = ProtoHelper.WriteString(nickname);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(1, "string"));
            bw.Write(__bytes);
        }

        __bytes = ProtoHelper.WriteString(signature);
        if (__bytes != null && __bytes.Length > 0)
        {
            bw.Write(ProtoHelper.WriteTag(2, "string"));
            bw.Write(__bytes);
        }

        return ms.ToArray();
    }
}

/// <summary>
/// // id = 5, desc = "心跳（30秒未发送心跳则判定断开连接）"
/// </summary>
public class U2LS_UserHeartBeatRequest : BaseMessage
{
    public override short MsgId => MessageDefine.U2LS_UserHeartBeatRequest;

    public override void Deserialize(byte[] data,ref int offset)
    {
        int newOffset = offset;
    }

    public override byte[] Serialize()
    {
        byte[] __bytes;
        using MemoryStream ms = new MemoryStream();
        using BinaryWriter bw = new BinaryWriter(ms);

        return ms.ToArray();
    }
}

/// <summary>
/// // id = 6
/// </summary>
public class LS2U_UserHearBeatResponse : BaseMessage
{
    public override short MsgId => MessageDefine.LS2U_UserHearBeatResponse;
    public long time_now;  // 服务器的当前时间戳(单位秒)
    private readonly uint tag_time_now = ProtoHelper.CalcTag(1, "int64");

    public override void Deserialize(byte[] data,ref int offset)
    {
        int newOffset = offset;
        newOffset = ProtoHelper.ReadRawTagInPlace(data, offset, out uint tag_read_time_now);
        if (tag_time_now == tag_read_time_now)
        {
            offset = newOffset;
            time_now = ProtoHelper.ReadInt64(data, ref offset);
        }

    }

    public override byte[] Serialize()
    {
        byte[] __bytes;
        using MemoryStream ms = new MemoryStream();
        using BinaryWriter bw = new BinaryWriter(ms);

        __bytes = ProtoHelper.WriteInt64(time_now);
        {
            bw.Write(ProtoHelper.WriteTag(1, "int64"));
            bw.Write(__bytes);
        }

        return ms.ToArray();
    }
}

